define(function (require, exports, module) {
    var $ = require("jquery");
    var angular = require("angular");
    var ui = require("ui");
    require('authorize');
    require("permission");
    require("angular-route");
    require("angular-ui");
    require("angular-interceptor");
    require("plupload");
    var util = require("util");
    require("./base-service");
    require("./source-service");
    require("./source-funs-service");
    require("./source-broker-service");
    var dialog = require("dialogplus");
    require('global');
    require("/static_public/js/angular_directive/clipboard");

    var app = angular.module('app', ['ngRoute', 'ngUI', 'ngInterceptor', 'ditchSourceModule', 'angular.directive.clipboard', 'ditchSourceFunsModule', 'ditchSourceBrokerModule', 'ditchSourceBaseModule']);

    app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/list', {templateUrl: 'source/list.html', controller: 'DitchSourceListController'})
            .when('/edit', {templateUrl: 'source/edit.html', controller: 'DitchSourceEditController'})
            .otherwise({redirectTo: '/list'});
    }]);

    app.controller('DitchSourceListController', ['$scope', '$routeParams', '$q', '$http', 'ditchSourceSvr', 'ditchSourceFunsSvr', 'ditchSourceBrokerSvr', 'ditchSourceBaseSvr', function ($scope, $routeParams, $q, $http, ditchSourceSvr, ditchSourceFunsSvr, ditchSourceBrokerSvr, ditchSourceBaseSvr) {
        $scope.baseSvr = ditchSourceBaseSvr;
        $scope.ditchSourceSvr = ditchSourceSvr;
        $scope.ditchSourceFunsSvr = ditchSourceFunsSvr;
        $scope.ditchSourceBrokerSvr = ditchSourceBrokerSvr;
        $scope.baseData = {
            channel_type: 0,
            button_name: '马上注册',
            font_color: 'black',
            button_color: 'white'
        };

        ditchSourceBaseSvr.initData();

        setTimeout(function () {
            // setTimeout 为了让路由先完成，防止 dom 元素闪动
            $scope.$apply(function () {
                ditchSourceSvr.initData();
            });
        }, 10);

        $scope.getDitchSourceData = function (page) {
            $scope.ditchSourceSvr.query(page, $scope.ditchSourceSvr.filter.pageSize, $scope.keyword);
        };

        $(document).on('click', function (e) {
            if ($(e.target).is('.showqr')) {
                return;
            }
            $scope.ditchSourceSvr.showQR = '';
            $scope.$applyAsync();
        });

        $scope.aftercopyNotify = function () {
            ui.showSucTip('复制成功');
        };

    }])

    app.controller('DitchSourceEditController', ['$scope', '$routeParams', function ($scope, $routeParams) {

    }])

    angular.bootstrap(document, ['app']);
});